package com.finger.wx.assistant.service;

import com.finger.wx.assistant.dao.CmdDao;
import com.finger.wx.assistant.dao.CmdDaoImpl;
import com.finger.wx.assistant.util.ToolProperties;
import com.finger.wx.assistant.util.ToolString;
import com.finger.wx.assistant.vo.Constant;
import com.finger.wx.assistant.vo.Point;

public class BaseService {
	CmdDao dao = new CmdDaoImpl();

	/**
	 * 执行命令之前，kill当前微信进程
	 */
	public void before() {
		dao.killApp("com.tencent.mm");
		dao.sleep(1000);
	}

	/**
	 * 回到主页面
	 */
	public void after() {
		dao.sleep(2000);
		dao.keyPress("home");
	}

	public Point getPointByConditions(String key, String text, String nclass) {
		String p = ToolProperties.readProp(Constant.cacheFile, key);
		Point point = null;
		try {
			if (!ToolString.isNoBlankAndNoNull(p)) {
				Point tmp = dao.findCompontLocation(text, nclass);
				point = tmp;
				ToolProperties.setProp(Constant.cacheFile, key, point.toString());
			} else {
				int x = Integer.parseInt(p.split(",")[0]);
				int y = Integer.parseInt(p.split(",")[1]);
				point = new Point(x, y);
			}
		} catch (RuntimeException e) {
			e.printStackTrace();
		}
		return point;
	}

	/**
	 * LoginUI 页面的帐号EditText坐标
	 * 
	 * @key login_account
	 * @return
	 */
	public Point getLoginAccountPoint() {
		String p = ToolProperties.readProp(Constant.cacheFile, "login_account");
		Point point = null;
		try {
			if (!ToolString.isNoBlankAndNoNull(p)) {
				Point tmp = dao.findCompontLocation("帐号", "android.widget.TextView");
				point = new Point(tmp.getX()*3, tmp.getY());
				ToolProperties.setProp(Constant.cacheFile, "login_account", point.toString());
			} else {
				int x = Integer.parseInt(p.split(",")[0]);
				int y = Integer.parseInt(p.split(",")[1]);
				point = new Point(x, y);
			}
		} catch (RuntimeException e) {
			e.printStackTrace();
		}
		return point;
	}

	/**
	 * LoginUI 页面的密码EditText坐标
	 * 
	 * @key login_pwd
	 * @return
	 */
	public Point getLoginPwdPoint() {
		String p = ToolProperties.readProp(Constant.cacheFile, "login_pwd");
		Point point = null;
		try {
			if (!ToolString.isNoBlankAndNoNull(p)) {
				Point tmp = dao.findCompontLocation("密码", "android.widget.TextView");
				point = new Point(tmp.getX()*3, tmp.getY());
				ToolProperties.setProp(Constant.cacheFile, "login_pwd", point.toString());
			} else {
				int x = Integer.parseInt(p.split(",")[0]);
				int y = Integer.parseInt(p.split(",")[1]);
				point = new Point(x, y);
			}
		} catch (RuntimeException e) {
			e.printStackTrace();
		}
		return point;
	}

	/**
	 * LoginUI 页面的登录Button坐标
	 * 
	 * @key login_btn
	 * @return
	 */
	public Point getLoginBtnPoint() {
		return getPointByConditions("login_btn", "登录", "android.widget.Button");
	}

	/**
	 * 菜单项-微信(聊天记录列表)坐标
	 * 
	 * @key menu_chats
	 * @return
	 */
	public Point getMenuChatsPoint() {
		return getPointByConditions("menu_chats", "微信", "android.widget.TextView");
	}

	/**
	 * 菜单项-通讯录坐标
	 * 
	 * @key menu_contacts
	 * @return
	 */
	public Point getMenuContactsPoint() {
		return getPointByConditions("menu_contacts", "通讯录", "android.widget.TextView");
	}

	/**
	 * 菜单项-发现坐标
	 * 
	 * @key menu_discovers
	 * @return
	 */
	public Point getMenuDiscoverPoint() {
		return getPointByConditions("menu_discovers", "发现", "android.widget.TextView");
	}

	/**
	 * 菜单项-我坐标
	 * 
	 * @key menu_me
	 * @return
	 */
	public Point getMenuMePoint() {
		return getPointByConditions("menu_me", "我", "android.widget.TextView");
	}

	/**
	 * 顶部工具-搜索坐标
	 * 
	 * @key head_search
	 * @return
	 */
	public Point getHeadSearchPoint() {
		return getPointByConditions("head_search", "搜索", "android.widget.TextView");
	}

	/**
	 * 顶部工具-更多功能按钮(+号)坐标
	 * 
	 * @key head_more
	 * @return
	 */
	public Point getHeadMorePoint() {
		return getPointByConditions("head_more", "更多功能按钮", "android.widget.RelativeLayout");
	}

	/**
	 * 顶部工具-更多(+号)-群聊坐标
	 * 
	 * @key head_more_groupchats
	 * @return
	 */
	public Point getHeadMoreGroupChatsPoint() {

		return null;
	}

	/**
	 * 顶部工具-更多(+号)-添加朋友坐标
	 * 
	 * @key head_more_addfriends
	 * @return
	 */
	public Point getHeadMoreAddFriendsPoint() {

		return null;
	}

	/**
	 * 顶部工具-更多(+号)-扫一扫坐标
	 * 
	 * @key head_more_scanqr
	 * @return
	 */
	public Point getHeadMoreScanQRPoint() {

		return null;
	}

	/**
	 * 通讯录-新的朋友坐标
	 * 
	 * @key contacts_newfriends
	 * @return
	 */
	public Point getContactsNewFriendsPoint() {

		return null;
	}

	/**
	 * 通讯录-群聊坐标
	 * 
	 * @key contacts_savedgroups
	 * @return
	 */
	public Point getContactsSavedGroupsPoint() {

		return null;
	}

	/**
	 * 通讯录-标签坐标
	 * 
	 * @key contacts_tags
	 * @return
	 */
	public Point getContactsTagsPoint() {

		return null;
	}

	/**
	 * 通讯录-公众号坐标
	 * 
	 * @key contacts_officAccount
	 * @return
	 */
	public Point getContactsOfficialAccountPoint() {

		return null;
	}

	/**
	 * 发现-朋友圈坐标
	 * 
	 * @key discover_moments
	 * @return
	 */
	public Point getDiscoverMomentsPoint() {
		return getPointByConditions("discover_moments", "朋友圈", "android.widget.TextView");
	}

	/**
	 * 发现-扫一扫坐标
	 * 
	 * @key discover_scanqr
	 * @return
	 */
	public Point getDiscoverQRPoint() {
		return getPointByConditions("discover_scanqr", "扫一扫", "android.widget.TextView");
	}

	/**
	 * 发现-摇一摇坐标
	 * 
	 * @key discover_shake
	 * @return
	 */
	public Point getDiscoverShakePoint() {
		return getPointByConditions("discover_shake", "摇一摇", "android.widget.TextView");
	}

	/**
	 * 发现-附近的人坐标
	 * 
	 * @key discover_nearby
	 * @return
	 */
	public Point getDiscoverPeopleNearByPoint() {
		return getPointByConditions("discover_nearby", "附近的人", "android.widget.TextView");
	}

	/**
	 * 发现-附近的人-开始查看按钮坐标
	 * 
	 * @key discover_nearby_lookbtn
	 * @return
	 */
	public Point getPeopleNearByLookBtnPoint() {
		return getPointByConditions("discover_nearby_lookbtn", "开始查看", "android.widget.Button");
	}
	
	/**
	 * 发现-附近的人-开始查看-提示框(下次不提示)坐标
	 * 
	 * @key discover_nearby_tip_checkbox
	 * @return
	 */
	public Point getPeopleNearByTipCheckBoxPoint() {
		return getPointByConditions("discover_nearby_tip_checkbox", "下次不提示", "android.widget.CheckBox");
	}
	
	/**
	 * 发现-附近的人-开始查看-提示框(确定)坐标
	 * 
	 * @key discover_nearby_tip_confirmbtn
	 * @return
	 */
	public Point getPeopleNearByTipConfirmBtnPoint() {
		return getPointByConditions("discover_nearby_tip_confirmbtn", "确定", "android.widget.Button");
	}
	
	/**
	 * 发现-附近的人-查看附近的人按钮坐标
	 * 
	 * @key discover_nearby_looknearbtn
	 * @return
	 */
	public Point getPeopleNearByLookNearBtnPoint() {
		return getPointByConditions("discover_nearby_looknearbtn", "查看附近的人", "android.widget.Button");
	}
	
	/**
	 * 附近的人列表页面-更多坐标
	 * 
	 * @key nearbyui_more
	 * @return
	 */
	public Point getNearByUIMorePoint() {
		return getPointByConditions("nearbyui_more", "更多", "android.widget.TextView");
	} 
	
	/**
	 * 附近的人列表页面-更多-只看女生坐标
	 * 
	 * @key nearbyui_more_only_woman
	 * @return
	 */
	public Point getNearByUIOnlyLookWomanPoint() {
		return getPointByConditions("nearbyui_more_only_woman", "只看女生", "android.widget.TextView");
	} 
	
	/**
	 * 附近的人列表页面-更多-只看男生坐标
	 * 
	 * @key nearbyui_more_only_man
	 * @return
	 */
	public Point getNearByUIOnlyLookManPoint() {
		return getPointByConditions("nearbyui_more_only_man", "只看男生", "android.widget.TextView");
	} 
	
	/**
	 * 附近的人列表页面-更多-查看全部坐标
	 * 
	 * @key nearbyui_more_all
	 * @return
	 */
	public Point getNearByUILookAllPoint() {
		return getPointByConditions("nearbyui_more_all", "查看全部", "android.widget.TextView");
	} 
	
	/**
	 * 附近的人列表页面-更多-附近打招呼的人坐标
	 * 
	 * @key nearbyui_more_near_sayHi
	 * @return
	 */
	public Point getNearByUINearSayHiPoint() {
		return getPointByConditions("nearbyui_more_near_sayHi", "附近打招呼的人", "android.widget.TextView");
	} 
	
	/**
	 * 附近的人列表页面-更多-清除位置并退出坐标
	 * 
	 * @key nearbyui_more_clearlocation
	 * @return
	 */
	public Point getNearByUIClearLocationPoint() {
		return getPointByConditions("nearbyui_more_clearlocation", "清除位置并退出", "android.widget.TextView");
	} 
	
	/**
	 * 发现-漂流瓶坐标
	 * 
	 * @key discover_messagebottle
	 * @return
	 */
	public Point getDiscoverMessageInBottlePoint() {
		return getPointByConditions("discover_messagebottle", "漂流瓶", "android.widget.TextView");
	}

	/**
	 * 我-设置坐标
	 * 
	 * @key me_setting
	 * @return
	 */
	public Point getMeSettingPoint() {
		return getPointByConditions("me_setting", "设置", "android.widget.TextView");
	}

	/**
	 * 我-设置-退出坐标
	 * 
	 * @key me_setting_logout
	 * @return
	 */
	public Point getMeSettingLogoutPoint() {
		return getPointByConditions("me_setting_logout", "退出", "android.widget.TextView");
	}

	/**
	 * 退出当前帐号提示框，退出当前帐号选项的坐标
	 * 
	 * @key logout_tip
	 * @return
	 */
	public Point getLogoutTipPoint() {
		return getPointByConditions("logout_tip", "退出当前帐号", "android.widget.TextView");
	}

	/**
	 * 退出微信确认提示框,确认按钮的坐标
	 * 
	 * @key logout_confirm_tip
	 * @return
	 */
	public Point getLogoutConfirmTipPoint() {
		return getPointByConditions("logout_confirm_tip", "退出", "android.widget.Button");
	}

	/**
	 * 我-设置-聊天坐标
	 * 
	 * @key me_setting_chat
	 * @return
	 */
	public Point getMeSettingChatPoint() {
		return getPointByConditions("me_setting_chat", "聊天", "android.widget.TextView");
	}

	/**
	 * 我-设置-聊天-清空聊天记录坐标
	 * 
	 * @key me_setting_chat_clear
	 * @return
	 */
	public Point getMeSettingChatClearPoint() {
		return getPointByConditions("me_setting_chat_clear", "清空聊天记录", "android.widget.TextView");
	}

	/**
	 * 清空聊天记录提示框(清空按钮)坐标
	 * 
	 * @key clear_chats_tip
	 * @return
	 */
	public Point getClearChatsTipPoint() {
		return getPointByConditions("clear_chats_tip", "清空", "android.widget.Button");
	}

}
